package com.fortune.service.impl;

import com.fortune.common.paging.PagingDto;
import com.fortune.dao.StoreMgtDao;
import com.fortune.dto.in.storeMgt.StoreAddDto;
import com.fortune.dto.in.storeMgt.StoreEditDto;
import com.fortune.dto.in.storeMgt.StoreFindDto;
import com.fortune.service.StoreMgtService;
import com.fortune.vo.storeMgt.StoreInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2018/5/24 0024.
 */
@Service
public class StoreMgtServiceImpl implements StoreMgtService{

    @Autowired
    private StoreMgtDao storeMgtDao;

    /**
     * 仓库列表
     * @param storeFindDto
     * @return
     */
    @Override
    public List<StoreInfo> findStoreList(StoreFindDto storeFindDto,String mid) {
        List<StoreInfo> list = storeMgtDao.findStoreList(storeFindDto,mid);
        for(StoreInfo storeInfo:list){
           Integer count = storeMgtDao.findInStock(storeInfo.getId());
           if(count == null || count == 0){
               storeInfo.setIsHave("NO");
           }else{
               storeInfo.setIsHave("YES");
           }
        }
        return list;
    }

    @Override
    public int findStoreListCount(StoreFindDto storeFindDto,String mid) {
        return storeMgtDao.findStoreListCount(storeFindDto,mid);
    }

    @Override
    public int insertStore(StoreAddDto storeAddDto,String mid,String id) {
        int find = storeMgtDao.findRepeat(storeAddDto.getName(),mid);
        if(find > 0){
            return -1;
        }else{
            return storeMgtDao.insertStore(storeAddDto,mid,id);
        }
    }

    @Override
    public int editStore(StoreEditDto storeEditDto, String mid) {
        int find = storeMgtDao.findRepeats(storeEditDto.getName(),mid,storeEditDto.getId());
        if(find > 0){
            return -1;
        }else {
            return storeMgtDao.editStore(storeEditDto, mid);
        }
    }

    @Override
    public int deleteStore(String mid, String storeId) {
        return storeMgtDao.deleteStore(mid,storeId);
    }
}
